/**
 * Copyright (C) Skywares Information Technology, LTD. 
 * All Rights Reserved.
 *
 * LoginController.java created on 2020年2月2日 下午12:48:53 by Lyon Lu 
 */
package com.mvc.server.miaosha.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.mvc.server.miaosha.pojo.MiaoshaUser;
import com.mvc.server.miaosha.service.MiaoshaUserService;
import com.mvc.server.miaosha.vo.LoginVo;
import com.mvc.server.result.CommonResult;

import lombok.extern.log4j.Log4j2;

/**
 * <pre>
 * Description:
 * 
 * @author Lyon Lu
 * @date 2020年2月2日 下午12:48:53
 *
 * </pre>
 */
@Log4j2
@Controller
@RequestMapping("/login")
public class LoginController {
	
	@Resource
	private MiaoshaUserService miaoshaUserService;
	
	@RequestMapping("/to_login")
    public String toLogin() {
        return "login";
    }
    
    @RequestMapping("/do_login")
    @ResponseBody
    public CommonResult<String> doLogin(HttpServletResponse response, @Valid LoginVo loginVo){
    	
    	log.info(loginVo.toString());
    	
    	//登录
    	String token = miaoshaUserService.login(response, loginVo);
    	return CommonResult.success(token);
    }
    
    @RequestMapping("/do_get_user")
    @ResponseBody
    public CommonResult<MiaoshaUser> doGetUser(MiaoshaUser user){
    	log.info(user);
    	return CommonResult.success(user);
    }
}
